package com.codeest.geeknews.widget.transform;

import android.support.v4.view.ViewPager;
import android.view.View;

public class ParallaxPageTransformer implements ViewPager.PageTransformer {
    private float parallaxSpeed = 0.5f;

    private final int parallaxViewId;

    public ParallaxPageTransformer(final int parallaxViewId) {
        this.parallaxViewId = parallaxViewId;
    }

    @Override
    public void transformPage(View view, float pagePos) {
        View parallaxView = view.findViewById(parallaxViewId);
        if (parallaxView == null) {
            return;
        }
        if (pagePos <= -1 || pagePos >= 1) {
            return;
        }
        parallaxView.setTranslationX(-pagePos * parallaxSpeed * view.getWidth());
    }

    public void setParallaxSpeed(float parallaxSpeed) {
        this.parallaxSpeed = parallaxSpeed;
    }
}
